package com.situ.personal.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

// filterName就是这个Filter的名字
// urlPatterns:代表要拦截的路径，/*代表拦截所有
// @WebFilter(filterName = "helloFilter1", urlPatterns = {"/*"})
public class HelloFilter1 implements Filter{
	
	public HelloFilter1() {
		System.out.println("HelloFilter1.HelloFilter1()");
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		System.out.println("HelloFilter1.init()");
	}

	// doFilter类似于Servlet的service方法
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("HelloFilter1.doFilter() before");
		
		// 执行下一个过滤器，如果没有过滤器就访问要访问的Servlet
		chain.doFilter(request, response);
		
		System.out.println("HelloFilter1.doFilter() after");
	}

	@Override
	public void destroy() {
		System.out.println("HelloFilter1.destroy()");
	}

}
